<?php

//session_start();
$type = isset($_GET['type']) ? $_GET['type'] : "taocan_recharge";

if ($type == "surplus_recharge") { //剩余流量查询
    $phone = $_GET['phone'];
    $monthDay = date("Ym01");
    $res = file_get_contents("http://120.25.126.95:8033/cms/recharge/rechargeInterfaceDX/queryPakage.do?phone={$phone}&monthDate={$monthDay}");
    $res = json_decode($res, true);
    if (isset($res['code']) && $res['code'] == "-1") {
        echo json_encode(array('success' => false, 'message' => "你输入的卡号无效"));
        exit;
    }
    echo json_encode(array('success' => true, 'data' => $res['result']));
}elseif ($type=="shopMifiCard") {
  $res = file_get_contents("http://120.25.126.95:8033/cms/shop/shopMifiCard/getShopMifiCardList.do");
  $res = json_decode($res, true);
  if (!$res || isset($res['code']) && $res['code'] == "-1") {
      echo json_encode(array('success' => false, 'message' => "网络请求错误"));
      exit;
  }
    echo json_encode(array('success' => true, 'data' => $res['result']));
}
 elseif ($type == "paycheck_record") { //充值记录查询
    $phone = $_GET['phone'];
    $record = file_get_contents("http://120.25.126.95:8033/cms/recharge/rechargeBase/page.do?phone={$phone}");
    $res = json_decode($record, true);
    if (isset($res['code']) && $res['code'] == "-1") {
        echo json_encode(array('success' => false, 'message' => "你输入的卡号无效"));
        exit;
    }

   echo json_encode(array('success' => true, 'data' => $res['result']));

} elseif($type=="traffic_query"){
  //http://120.25.126.95:8033/cms/recharge/rechargeInterfaceDX/queryTraffic.do?phone=8986031640200654947
  $phone = $_GET['phone'];
  $record = file_get_contents("http://120.25.126.95:8033/cms/recharge/rechargeInterfaceDX/queryTraffic.do?phone={$phone}");
  $res = json_decode($record, true);
  if (isset($res['code']) && $res['code'] == "-1") {
      echo json_encode(array('success' => false, 'message' => "你输入的卡号无效"));
      exit;
  }

 echo json_encode(array('success' => true, 'data' => $res['result']));

}else { //充值流量查询
    $phone = $_GET['phone'];
    $month = file_get_contents("http://120.25.126.95:8033/cms/recharge/rechargeItem/getRechargeItemList.do?type=1&phone={$phone}");
    $res = json_decode($month, true);
    if (isset($res['code']) && $res['code'] == "-1") {
        echo json_encode(array('success' => false, 'message' => "你输入的卡号无效"));
        exit;
    }
    $year = file_get_contents("http://120.25.126.95:8033/cms/recharge/rechargeItem/getRechargeItemList.do?type=2&phone={$phone}");
  //  $record = file_get_contents("http://120.25.126.95:8033/cms/recharge/rechargeBase/page.do?phone={$phone}");
  //  $res = json_decode($record, true);


    echo json_encode(array('month' => json_decode($month, true),
        'year' => json_decode($year, true),
      //  'record' => json_decode($record, true),
        'phone' => $phone,
        'success' => true
    ));
}
